import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '*',
    redirect: '/home',
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('@/views/Home'),
    meta: { show: true }
  },
  {
    path: '/design',
    name: 'design',
    component: () => import('@/views/Design'),
    meta: { show: true }
  },
  {
    path: '/userCenter',
    name: 'Center',
    component: () => import('@/views/Center'),
    meta: { show: true }
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/Search')
  },
  {
    path: '/scene',
    name: 'scene',
    component: () => import('@/views/Scene')
  },
  {
    path: '/detail/:id',
    name: 'detail',
    component: () => import('@/views/Detail')
  },
  {
    path: '/theme',
    name: 'theme',
    component: () => import('@/views/Theme')
  },


]

let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;

//手写push replace 防止重复进入报错
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    originPush.call(this, location, resolve, reject)
  }
  else {
    originPush.call(this, location, () => { }, () => { })

  }
}
VueRouter.prototype.replace = function (location, resolve, reject) {
  if (resolve && reject) {
    originReplace.call(this, location, resolve, reject)
  }
  else {
    originReplace.call(this, () => { }, () => { })

  }
}
const router = new VueRouter({
  routes
})

export default router
